package com.itWaiLong.Utils;


import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Date;
import java.util.Map;

public class JWTUtils {
    private static final String IT_LONG = "itLong";

    //生成token
    public static String SetToken(Map<String, Object> claims) {
        return JWT.create()
                .withClaim("claims",claims)
                .withExpiresAt(new Date(System.currentTimeMillis() + 1000 * 60 * 60))
                .sign(Algorithm.HMAC256(IT_LONG));
    }

    //解析token
    public static Map<String, Object> getClaims(String token) {
        return JWT.require(Algorithm.HMAC256(IT_LONG))
                .build()
                .verify(token)
                .getClaim("claims")
                .asMap();
    }
}
